package me.zhengjie.deepseek.controller;

import io.swagger.annotations.ApiOperation;
import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.annotation.Log;
import me.zhengjie.deepseek.config.PromptTemplateProperties;
import me.zhengjie.deepseek.dto.GenerateRequest;
import me.zhengjie.deepseek.dto.Message;
import me.zhengjie.deepseek.service.DeepSeekClientService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.List;

@RestController
@RequestMapping("/api/ai")
public class AIController {
    private final DeepSeekClientService aiService;
    private final PromptTemplateProperties templates;

    public AIController(DeepSeekClientService aiService,
                        PromptTemplateProperties templates) {
        this.aiService = aiService;
        this.templates = templates;
    }
    @GetMapping(path = "/generate-poem", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    @Log("生成诗歌")
    @ApiOperation("生成诗歌")
    @AnonymousAccess
    public Flux<String> generatePoem(@RequestParam String prompt) {
        List<Message> messages = List.of(
                new Message("system", templates.getPoemSystem()),
                new Message("user", prompt)
        );
        return aiService.generateText(messages);
    }

    @GetMapping(path = "/analyze-poem", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    @Log("分析诗词")
    @ApiOperation("分析诗词")
    @AnonymousAccess
    public Flux<String> analyzePoem(@RequestParam String prompt) {
        List<Message> messages = List.of(
                new Message("system", templates.getAnalyzeSystem()),
                new Message("user", prompt)
        );
        return aiService.generateText(messages);
    }

    @GetMapping(path = "/test", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    @Log("测试功能")
    @ApiOperation("测试功能")
    @AnonymousAccess
    public Flux<String> test(@RequestParam String prompt) {
        List<Message> messages = List.of(
                new Message("system", "You are a helpful assistant"),
                new Message("user", prompt)
        );
        return aiService.generateText(messages);
    }
}
